home *** CD-ROM | disk | FTP | other *** search
/ Gurewich OLE Controls for Visual Basic 4 / Gurewich OLE Controls for Visual Basic 4.iso / ocxprog / programs / ch13 / speaker.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-08-24  |  11.3 KB  |  362 lines

  1. VERSION 4.00
  2. Begin VB.Form frmSpeaker 
  3.    Caption         =   "The Speaker Program"
  4.    ClientHeight    =   3375
  5.    ClientLeft      =   1155
  6.    ClientTop       =   1545
  7.    ClientWidth     =   7575
  8.    Height          =   4065
  9.    Icon            =   "SPEAKER.frx":0000
  10.    Left            =   1095
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3375
  13.    ScaleWidth      =   7575
  14.    Top             =   915
  15.    Width           =   7695
  16.    Begin VB.CommandButton cmdFast 
  17.       Caption         =   "&Fastest"
  18.       Height          =   435
  19.       Left            =   6720
  20.       TabIndex        =   10
  21.       Top             =   1620
  22.       Width           =   735
  23.    End
  24.    Begin VB.CommandButton cmdNormal 
  25.       Caption         =   "&Normal"
  26.       Height          =   435
  27.       Left            =   2280
  28.       TabIndex        =   9
  29.       Top             =   1620
  30.       Width           =   735
  31.    End
  32.    Begin VB.CommandButton cmdSlow 
  33.       Caption         =   "S&lowest"
  34.       Height          =   435
  35.       Left            =   120
  36.       TabIndex        =   8
  37.       Top             =   1620
  38.       Width           =   735
  39.    End
  40.    Begin VB.HScrollBar hsbSpeed 
  41.       Height          =   255
  42.       Left            =   120
  43.       Max             =   200
  44.       Min             =   50
  45.       TabIndex        =   5
  46.       Top             =   1320
  47.       Value           =   100
  48.       Width           =   7335
  49.    End
  50.    Begin VB.CommandButton cmdRewind 
  51.       Caption         =   "&Rewind"
  52.       Height          =   855
  53.       Left            =   5880
  54.       TabIndex        =   4
  55.       Top             =   2400
  56.       Width           =   1575
  57.    End
  58.    Begin VB.CommandButton cmdPlayMultitask 
  59.       Caption         =   "Play &MultiTask"
  60.       Height          =   855
  61.       Left            =   2040
  62.       TabIndex        =   3
  63.       Top             =   2400
  64.       Width           =   1575
  65.    End
  66.    Begin VB.CommandButton cmdStop 
  67.       Caption         =   "&Stop"
  68.       Height          =   855
  69.       Left            =   3960
  70.       TabIndex        =   2
  71.       Top             =   2400
  72.       Width           =   1575
  73.    End
  74.    Begin VB.CommandButton cmdPlay 
  75.       Caption         =   "&Play"
  76.       Height          =   855
  77.       Left            =   120
  78.       TabIndex        =   1
  79.       Top             =   2400
  80.       Width           =   1575
  81.    End
  82.    Begin VB.Label lblSpeed 
  83.       Caption         =   "Speed: 100"
  84.       BeginProperty Font 
  85.          name            =   "MS Sans Serif"
  86.          charset         =   0
  87.          weight          =   400
  88.          size            =   12
  89.          underline       =   0   'False
  90.          italic          =   0   'False
  91.          strikethrough   =   0   'False
  92.       EndProperty
  93.       Height          =   300
  94.       Left            =   120
  95.       TabIndex        =   7
  96.       Top             =   960
  97.       Width           =   1935
  98.    End
  99.    Begin TegoswLibCtl.Tegosw swExit 
  100.       Height          =   630
  101.       Left            =   0
  102.       TabIndex        =   6
  103.       Top             =   0
  104.       Width           =   525
  105.       _version        =   65536
  106.       _extentx        =   926
  107.       _extenty        =   1111
  108.       _stockprops     =   64
  109.       value           =   -1  'True
  110.    End
  111.    Begin MSComDlg.CommonDialog CommonDialog1 
  112.       Left            =   1800
  113.       Top             =   120
  114.       _Version        =   65536
  115.       _ExtentX        =   847
  116.       _ExtentY        =   847
  117.       _StockProps     =   0
  118.       CancelError     =   -1  'True
  119.    End
  120.    Begin TegspkrLib.TegoSpeaker TegoSpeaker1 
  121.       Height          =   600
  122.       Left            =   720
  123.       TabIndex        =   0
  124.       Top             =   120
  125.       Width           =   930
  126.       _version        =   65536
  127.       _extentx        =   1640
  128.       _extenty        =   1058
  129.       _stockprops     =   0
  130.    End
  131.    Begin VB.Menu mnuFile 
  132.       Caption         =   "&File"
  133.       Begin VB.Menu mnuOpen 
  134.          Caption         =   "&Open..."
  135.       End
  136.       Begin VB.Menu mnuClose 
  137.          Caption         =   "&Close"
  138.       End
  139.       Begin VB.Menu mnuSep1 
  140.          Caption         =   "-"
  141.       End
  142.       Begin VB.Menu mnuInfo 
  143.          Caption         =   "&Info..."
  144.       End
  145.       Begin VB.Menu mnuSep2 
  146.          Caption         =   "-"
  147.       End
  148.       Begin VB.Menu mnuExit 
  149.          Caption         =   "E&xit"
  150.       End
  151.    End
  152.    Begin VB.Menu mnuHelp 
  153.       Caption         =   "&Help"
  154.       Begin VB.Menu mnuAbout 
  155.          Caption         =   "About..."
  156.       End
  157.    End
  158. Attribute VB_Name = "frmSpeaker"
  159. Attribute VB_Creatable = False
  160. Attribute VB_Exposed = False
  161. ' All variables must be declared.
  162. Option Explicit
  163. Private Sub cmdFast_Click()
  164. ' Set the hsbSpeed scrollbar to its maximum value.
  165. hsbSpeed.Value = hsbSpeed.Max
  166. End Sub
  167. Private Sub cmdNormal_Click()
  168. ' Set the hsbSpeed scrollbar to a value of 100.
  169. hsbSpeed.Value = 100
  170. End Sub
  171. Private Sub cmdPlay_Click()
  172. ' Play from the beginning of the WAV file until
  173. ' the end of the WAV file without multitasking,
  174. ' and disable the mouse during playback.
  175. TegoSpeaker1.Play 0, -1, 0, False
  176. End Sub
  177. Private Sub cmdPlayMultitask_Click()
  178. ' Play from the current playback position until
  179. ' the end of the WAV file, with a 300 milliseconds
  180. ' multitask interval, and enable the mouse during
  181. ' playback.
  182. TegoSpeaker1.Play -1, -1, 300, True
  183. End Sub
  184. Private Sub cmdRewind_Click()
  185. ' Rewind the playback position to the beginning
  186. ' of the WAV file.
  187. TegoSpeaker1.Seek 0
  188. End Sub
  189. Private Sub cmdSlow_Click()
  190. ' Set the hsbSpeed scrollbar to its minimum value.
  191. hsbSpeed.Value = hsbSpeed.Min
  192. End Sub
  193. Private Sub cmdStop_Click()
  194. ' Stop the playback.
  195. TegoSpeaker1.Stop
  196. End Sub
  197. Private Sub Form_Load()
  198. TegoSpeaker1.Visible = False
  199. ' Initially, no WAV file is open, so we execute the
  200. ' mnuClose_Click() procedure to disable various
  201. ' controls.
  202. mnuClose_Click
  203. End Sub
  204. Private Sub hsbSpeed_Change()
  205.    ' Updtae the lblSpeed label with the new value of
  206.    ' the hsbSpeed scrollbar.
  207.    lblSpeed.Caption = "Speed: " + Str(hsbSpeed.Value)
  208.    ' Change the playback speed to the speed specified
  209.    ' by the hsbSpeed scrollbar.
  210.    TegoSpeaker1.SetSpeed hsbSpeed.Value
  211. End Sub
  212. Private Sub hsbSpeed_Scroll()
  213.    ' Execute the hsbSpeed_Change() procedure.
  214.    hsbSpeed_Change
  215. End Sub
  216. Private Sub mnuAbout_Click()
  217.    Dim Title
  218.    Dim msg
  219.    Dim CR
  220.    CR = Chr(13) + Chr(10)
  221.    ' The title of the About message box.
  222.    Title = "About the Speaker Program"
  223.    ' Prepare the message of the About message box.
  224.    msg = "This program was written with Visual "
  225.    msg = msg + "Basic for Windows, using the "
  226.    msg = msg + "TegoSoft Speaker OCX control. "
  227.    msg = msg + CR + CR
  228.    msg = msg + "The TegoSoft Speaker OCX control "
  229.    msg = msg + "is part of the TegoSoft OCX Control "
  230.    msg = msg + "Kit - a collection of various OCX controls. "
  231.    msg = msg + CR + CR
  232.    msg = msg + "For more information about the "
  233.    msg = msg + "TegoSoft OCX Control Kit, contact TegoSoft "
  234.    msg = msg + "at:"
  235.    msg = msg + CR + CR
  236.    msg = msg + "TegoSoft Inc." + CR
  237.    msg = msg + "P.O. Box 389" + CR
  238.    msg = msg + "Bellmore, NY 11710"
  239.    msg = msg + CR + CR
  240.    msg = msg + "Phone: (516)783-4824"
  241.    ' Display the About message box.
  242.    MsgBox msg, vbInformation, Title
  243. End Sub
  244. Private Sub mnuClose_Click()
  245.     ' Close the WAV file.
  246.     TegoSpeaker1.Close
  247.     ' No WAV file is now open, so disable
  248.     ' the Speed, Close, Info, Play, Stop,
  249.     ' and Rewind controls.
  250.     hsbSpeed.Enabled = False
  251.     cmdSlow.Enabled = False
  252.     cmdFast.Enabled = False
  253.     cmdNormal.Enabled = False
  254.     mnuClose.Enabled = False
  255.     mnuInfo.Enabled = False
  256.     cmdPlay.Enabled = False
  257.     cmdPlayMultitask.Enabled = False
  258.     cmdStop.Enabled = False
  259.     cmdRewind.Enabled = False
  260.     ' Set the title of the program's window.
  261.     Me.Caption = "The Speaker Program"
  262. End Sub
  263. Private Sub mnuExit_Click()
  264. ' Terminate the program.
  265. Unload Me
  266. End Sub
  267. Private Sub mnuInfo_Click()
  268. Dim Title
  269. Dim msg
  270. Dim CRLF
  271. CRLF = Chr(13) + Chr(10)
  272. ' The title of the Info message box.
  273. Title = "WAV File Information"
  274. ' Prepare the message for the Info message box.
  275. msg = "File Name: " + TegoSpeaker1.GetWavFilename
  276. msg = msg + CRLF
  277. msg = msg + "File Length: " + Str(TegoSpeaker1.GetLength) + " samples."
  278. msg = msg + CRLF
  279. msg = msg + "Sampling Rate: " + Str(TegoSpeaker1.GetSamplingRate) + " Hz."
  280. msg = msg + CRLF
  281. msg = msg + "Number of Bits Per Sample: " + Str(TegoSpeaker1.GetNumBits)
  282. msg = msg + CRLF
  283. msg = msg + "Number of Channels: " + Str(TegoSpeaker1.GetNumChannels)
  284. ' Display the Info message box.
  285. MsgBox msg, vbInformation, Title
  286. End Sub
  287. Private Sub mnuOpen_Click()
  288.     Dim msg
  289.     ' Set an error trap to detect the clicking
  290.     ' of the Cancel key of the Open dialog box.
  291.     On Error GoTo OpenError
  292.     ' Fill the items of the File Type list box of
  293.     ' the Open dialog box.
  294.     CommonDialog1.Filter = "All Files (*.*)|*.*|Wave Files (*.wav)|*.wav"
  295.     ' Set the default File Type to Wave Files (*.wav).
  296.     CommonDialog1.FilterIndex = 2
  297.     ' Display the Open dialog box.
  298.     CommonDialog1.Action = 1
  299.     ' Remove the error trap.
  300.     On Error GoTo 0
  301.     ' Open the WAV file that the user selected.
  302.     TegoSpeaker1.Open CommonDialog1.filename
  303.     ' If Open command failed, exit this procedure.
  304.     If TegoSpeaker1.GetErrorCode <> 0 Then
  305.        msg = "Cannot open " + CommonDialog1.filename
  306.        msg = msg + Chr(13) + Chr(10)
  307.        msg = msg + TegoSpeaker1.GetErrorMessage
  308.        MsgBox msg, 0, "ERROR"
  309.        mnuClose_Click
  310.        Exit Sub
  311.     End If
  312.     ' Display the name of the WAV file (without the path).
  313.     Me.Caption = "The Speaker Program - " + CommonDialog1.FileTitle
  314.     ' A WAV file is now open, so enable
  315.     ' the Speed, Close, Info, Play, Stop,
  316.     ' and Rewind controls.
  317.     hsbSpeed.Enabled = True
  318.     cmdSlow.Enabled = True
  319.     cmdFast.Enabled = True
  320.     cmdNormal.Enabled = True
  321.     mnuClose.Enabled = True
  322.     mnuInfo.Enabled = True
  323.     cmdPlay.Enabled = True
  324.     cmdPlayMultitask.Enabled = True
  325.     cmdStop.Enabled = True
  326.     cmdRewind.Enabled = True
  327.     ' Set the Speed scrollbar to normal speed.
  328.     hsbSpeed.Value = 100
  329.     ' Exit the procedure.
  330.     Exit Sub
  331. OpenError:
  332.     ' The user clicked the Cancel button of the
  333.     ' Open File dialog box.
  334.     Exit Sub
  335. End Sub
  336. Private Sub swExit_Click()
  337.    Dim Title
  338.    Dim Question
  339.    Dim Response
  340.    ' If the user turned the swExit switch OFF,
  341.    ' confirm that the user wants to exit the
  342.    ' program, and if so, exit the program.
  343.    If swExit.Value = False Then
  344.       Title = "Exit Program"
  345.       Question = "Are you sure you want to exit?"
  346.       Response = MsgBox(Question, vbYesNo + vbQuestion, Title)
  347.       If Response = vbYes Then
  348.          Unload Me
  349.       Else
  350.          swExit.Value = True
  351.       End If
  352.    End If
  353. End Sub
  354. Private Sub TegoSpeaker1_Done()
  355. ' If current playback position is end of file,
  356. ' rewind the playback position to the beginning of
  357. ' the file.
  358. If TegoSpeaker1.GetPosition = TegoSpeaker1.GetLength Then
  359.    TegoSpeaker1.Seek 0
  360. End If
  361. End Sub
  362.